package com.mall.market.controller;


import com.mall.commons.utils.CommonResult;
import com.mall.market.service.SmsHomeRecommendSubjectService;
import com.mall.model.domain.SmsHomeRecommendSubject;
import com.mall.model.dto.SmsHomeRecommendSubjectDto;
import com.mall.model.vo.CommonPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/recommendSubject")
public class SmsHomeRecommendSubjectController {
    @Autowired
    private SmsHomeRecommendSubjectService smsHomeRecommendSubjectService;

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(SmsHomeRecommendSubjectDto dto) {
        CommonPage commonPage = smsHomeRecommendSubjectService.list(dto);
        return CommonResult.success(commonPage);
    }

    //增
    @PostMapping("/create")
    public CommonResult create(@RequestBody List<SmsHomeRecommendSubject> smsHomeRecommendSubjectList) {
        smsHomeRecommendSubjectService.create(smsHomeRecommendSubjectList);
        return CommonResult.success(1);
    }

    //删
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List ids) {
        smsHomeRecommendSubjectService.delete(ids);
        return CommonResult.success(1);
    }

    //批量修改推荐状态
    @PostMapping("/update/recommendStatus")
    public CommonResult updateStatus(@RequestParam List<Integer> ids, Integer recommendStatus) {
        smsHomeRecommendSubjectService.updateStatus(ids, recommendStatus);
        return CommonResult.success("修改成功");
    }

    //修改排序
    @PostMapping("update/sort/{id}")
    public CommonResult updateSort(@PathVariable("id") Integer id, Integer sort) {
        smsHomeRecommendSubjectService.updateSort(id, sort);
        return CommonResult.success("修改成功");
    }

}
